<template>
  <div 
    class="status-indicator" 
    :class="[status, size, { 'is-animated': isAnimated }]"
    :style="customColor ? { '--indicator-color': customColor } : {}"
  >
    <div class="indicator-dot"></div>
    <div class="status-text">{{ statusText }}</div>
  </div>
</template>

<script>
export default {
  name: 'StatusIndicator',
  props: {
    status: {
      type: String,
      required: true,
      validator: value => ['disconnected', 'connecting', 'connected', 'reconnecting', 'failed'].includes(value)
    },
    size: {
      type: String,
      default: 'medium',
      validator: value => ['small', 'medium', 'large'].includes(value)
    },
    customColor: {
      type: String,
      default: ''
    },
    isAnimated: {
      type: Boolean,
      default: true
    }
  },
  
  computed: {
    statusText() {
      const statusMap = {
        disconnected: '断开连接',
        connecting: '连接中',
        connected: '已连接',
        reconnecting: '重连中',
        failed: '连接失败'
      };
      return statusMap[this.status] || '未知状态';
    }
  }
};
</script>

<style scoped>
.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  color: white;
  transition: all 0.3s ease;
}

.indicator-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--indicator-color, currentColor);
  transition: transform 0.3s ease, background 0.3s ease;
}

/* 状态颜色映射 */
.status-indicator.disconnected {
  --indicator-color: #e74c3c;
  background: rgba(231, 76, 60, 0.2);
}

.status-indicator.connecting {
  --indicator-color: #f39c12;
  background: rgba(243, 156, 18, 0.2);
  animation: pulse 1.5s infinite;
}

.status-indicator.connected {
  --indicator-color: #2ecc71;
  background: rgba(46, 204, 113, 0.2);
}

.status-indicator.reconnecting {
  --indicator-color: #3498db;
  background: rgba(52, 152, 219, 0.2);
  animation: pulse 2s infinite;
}

.status-indicator.failed {
  --indicator-color: #9b59b6;
  background: rgba(155, 89, 182, 0.2);
}

/* 尺寸变体 */
.status-indicator.small {
  font-size: 0.75rem;
  padding: 3px 6px;
}

.status-indicator.medium {
  font-size: 0.85rem;
  padding: 4px 8px;
}

.status-indicator.large {
  font-size: 1rem;
  padding: 6px 12px;
}

/* 动画定义 */
@keyframes pulse {
  0% {
    transform: scale(0.9);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(0.9);
    opacity: 0.8;
  }
}

/* 悬停效果 */
.status-indicator:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .status-indicator {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}
</style>